#ifndef I2C_H
#define I2C_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "delay.h"

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#define I2C_SCL_PIN			GPIO_Pin_7
#define I2C_SCL_PORT		GPIOB
#define I2C_SCL_CLK			RCC_APB2Periph_GPIOB

#define I2C_SDA_PIN			GPIO_Pin_6
#define I2C_SDA_PORT		GPIOB
#define I2C_SDA_CLK			RCC_APB2Periph_GPIOB

/* Exported macro ------------------------------------------------------------*/
#define SCL_High		GPIO_SetBits(I2C_SCL_PORT, I2C_SCL_PIN)
#define SCL_Low			GPIO_ResetBits(I2C_SCL_PORT, I2C_SCL_PIN)

#define SDA_High		GPIO_SetBits(I2C_SDA_PORT, I2C_SDA_PIN)
#define SDA_Low			GPIO_ResetBits(I2C_SDA_PORT, I2C_SDA_PIN)

#define SCL_Read		GPIO_ReadInputDataBit(I2C_SCL_PORT, I2C_SCL_PIN)
#define SDA_Read		GPIO_ReadInputDataBit(I2C_SDA_PORT, I2C_SDA_PIN)

#define I2C_Delay()		delay_us(4)

/* Exported variables ---------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void I2C_Start(void);
void I2C_Stop(void);
void I2C_Ack(void);
void I2C_NoAck(void);
int I2C_WaitAck(void);
void I2C_SendByte(uint8_t byte);
uint8_t I2C_RecvByte(void);

void i2c_init(void);
int i2c_writebyte(uint8_t addr, uint8_t reg, uint8_t data);
int i2c_write(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len);
int i2c_read(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf);


#endif

